<!-- <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>


<style>
	*{
		margin:0;padding:0;
	}
	body{overflow:hidden;}
	#canvas{
		background-color:black;
		/*width:100%;
		height:100vh;*/
	}
	
</style>


</head>
<body>


<canvas id="canvas" ></canvas>	
	
</body>


<script>
var canvas = document.querySelector('#canvas');
var ctx = canvas.getContext("2d");
var starlist = [];
function init(){
	canvas.width = window.innerWidth;
	canvas.height = window.innerHeight;
}
init();
window.onresize = init;


canvas.addEventListener('mousemove',function(e){
	starlist.push(new Star(e.offsetX,e.offsetY));
	console.log(starlist)
})


function random(min,max){
	return Math.floor((max-min)*Math.random()+ min);
}


function Star(x,y){
	this.x = x;
	this.y = y;
	this.vx = (Math.random()-0.5)*2.5;
	this.vy = (Math.random()-0.5)*2.5;
	this.color = 'rgb('+random(0,200)+','+random(0,200)+','+random(0,200)+')';
	this.a = 1;
	console.log(this.color);
	this.draw();
}
Star.prototype={
	draw:function(){
		ctx.beginPath();
		ctx.fillStyle = this.color;
		ctx.globalCompositeOperation='lighter'
		ctx.globalAlpha= this.a;
		ctx.arc(this.x,this.y,30,0,Math.PI*2,false);
		ctx.fill();
		this.updata();
	},
	updata(){
		this.x+=this.vx;
		this.y+=this.vy;
		this.a*=.98;
	}
}
console.log(new Star(150,200));
function render(){
	ctx.clearRect(0,0,canvas.width,canvas.height)
	
	starlist.forEach((item,i)=>{
		item.draw();
		if(item.a<0.05){
			starlist.splice(i,1);
		}
	})
	
	requestAnimationFrame(render);
}
render();	


</script>
<div style="text-align:center;">


</div>


</html> -->



<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		
		<!--<style type="text/css">
			*{
				margin: 0;
				padding: 0;
			}
			body{
				background: antiquewhite;
			}
			canvas{
				position: absolute;
				left: 0;
				right: 0;
				top: 0;
				bottom: 0;
				margin: auto;
				background: white;
				
			}         
		</style>      -->
		<!--  //居中-->
		<style>
	*{
		margin:0;padding:0;
	}
	body{overflow:hidden;}
	#canvas{
		background-color:black;
		/*width:100%;
		height:100vh;*/
	}
	
</style>
	</head>
	<body>
		 <!--//动画-->
		<!--<canvas  width="1000" height="1000"></canvas>  -->
		<canvas id="canvas" ></canvas>	
	</body>
	<script type="text/javascript">
		function init(){
	canvas.width = window.innerWidth;
	canvas.height = window.innerHeight;
}
init();
window.onresize = init;
		window.onload=function(){
			var oc=document.querySelector("canvas");
			if(oc.getContext){
				var ctx=oc.getContext("2d");   //获取画笔
				
				var arr=[];
//				将数组中的圆绘制到画布
                setInterval(function(){
                	ctx.clearRect(0,0,oc.width,oc.height);
             	console.log(arr);
//动画
                	for(var i=0;i<arr.length;i++){
                		arr[i].deg+=5;
                   arr[i].x=arr[i].startX+Math.sin(arr[i].deg*Math.PI/180)*arr[i].step*5;    
                   arr[i].y=arr[i].startY-        (arr[i].deg*Math.PI/180)*arr[i].step;  
                      if(arr[i].y<=10){
                      	arr.splice(i,1);
                      }
                      
 //随机气泡                     
//                    if(arr[i].alp<=0){
//                    	arr.splice(i,1);
//                    }
//              			arr[i].r++;
//              		arr[i].alp-=0.01;
                	}
                	
                	
                	
                	//绘制
                	for(var i=0;i<arr.length;i++){
                	ctx.save();
                	ctx.fillStyle="rgba("+arr[i].red+","+arr[i].green+","+arr[i].blue+","+arr[i].alp+")";
                	ctx.beginPath();
                	ctx.arc(arr[i].x,arr[i].y,arr[i].r,0,2*Math.PI);
                	ctx.fill();
                	ctx.restore();
                }
                },1000/60)
                
//				往arr中注入随机圆的信息
                setInterval(function(){
//              	随机圆心
                    var r=Math.random()*10+50;
                	var x=Math.random()*oc.width;
                	var y=oc.height-r;       //Math.random()*oc.height;
                	
                	var red = Math.round(Math.random()*255);
                	var green = Math.round(Math.random()*255);
                	var blue = Math.round(Math.random()*255);
                	var alp=0.5;
                	var deg=0;
                	var startX=x;
                	var startY=y;
                	
                	//控制曲线运动的运动形式
                	var step=Math.random()*20+10;
                	arr.push({
                		x:x,
                		y:y,
                		r:r,
                		red:red,
                		green:green,
                		blue:blue,
                		alp:alp,
                		deg:deg,
                		startX:startX,
                		startY:startY,
                		step:step
                		
                	})
                	
                },100)
				
				
				
				
				
			}
		}
	</script>
</html>